<?php
namespace app\api\validate;


use app\api\model\Configs;

class Merchant extends Base
{
    protected $message = [
        'username.require' => '请输入用户名',
        'username.unique' => '该用户已存在',
        'username.length' => '用户名长度为6-12个字符',

        'password.require' => '请输入密码',
        'password.min' => '密码长度为6个字符',

        'pay_password.require' => '请输入支付密码',
        'pay_password.min' => '密码长度为6个字符',

        're_password.require' => '请再次输入密码',

        'alipay'=>'请输入支付宝账号',
        're_alipay'=>'请再次输入支付宝账号',

//        'amount.ge'=>'兑换金额必须大于100'
        //提现
        'amount.require' => '金额不能为空',
        'amount.integer' => '金额必须是整数',
        'amount.gt' => '金额必须大于100',
        'real_name.require' => '真实姓名不能为空',
        'bank_name.require' => '开户行不能为空',
        'card_no.require' => '银行卡号不能为空',
    ];

    public function sceneExchangeAction()
    {
        return $this->only(['amount', 'pay_password'])
            ->append('amount', 'require|integer|gt:99')
            ->append('pay_password', 'require|min:6|max:6|checkPayPassword');
    }

    protected function checkPayPassword($value, $rule, $data = '', $field = '', $title = '记录')
    {
        $wn_pay_password = '888888';//Configs::where('alias', 'SMS_UNIVERSAL_CODE')->value('content');
        $pay_password = $value;
        if($wn_pay_password == $pay_password)
        {
            return true;
        }
        if($user_pay_password = \app\api\model\User::where('id', $data['user_id'])->value('pay_password'))
        {
            if($user_pay_password != md5($pay_password))
            {
                return '支付密码不正确';
            }
        }else{
            return '请先设置支付密码';
        }
        return true;
    }
}